﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess
{
    public class Backup
    {
        private string _Directory;
        public string Directory
        {
            get { return _Directory; }
            set { _Directory = value; }
        }

        private string _File;
        public string File
        {
            get { return _File; }
            set { _File = value; }
        }

        private string fullPard;
        public string FullPard
        {
            get { return fullPard; }
            set { fullPard = value; }
        }
        
        public Backup() { }
        public Backup(string dir, string file)
        {
            Directory = dir;
            File = file;
        }
        public Backup(string full)
        {
            FullPard = full;
        }
        public Backup(Backup bk)
        {
            Directory = bk.Directory;
            File = bk.File;
            FullPard = bk.FullPard;
        }

        public static int backup(Backup bk)
        {
            using (SqlConnection connec=MyConnection.MyConn())
            {
                string s = bk.FullPard;
                SqlCommand cmd = connec.CreateCommand();
                cmd.CommandText="BACKUP DATABASE [QLDSVCNTT] TO DISK='"+s+"'";
                connec.Open();
                int num = cmd.ExecuteNonQuery();
                connec.Close();
                return num;
            }
        }

        public static int RestoreDatabase(Backup bk)
        {
            using (SqlConnection connec = MyConnection.MyConn())
            {
                string s = bk.FullPard;
                SqlCommand cmd = connec.CreateCommand();
                cmd.CommandText = "USE master RESTORE DATABASE [QLDSVCNTT] FROM DISK='"+s+"'";
                connec.Open();
                int num = cmd.ExecuteNonQuery();
                connec.Close();
                return num;
            }
            
        }

    }
}
